import moment from 'moment'

export const timeFormatter = (timestamp: number, formatter = 'yyyy/MM/DD') => {
  if (timestamp <= 0) {
    return ''
  }
  return moment(timestamp * 1000).format(formatter)
}

export const durationFormatter = (duration: number) => {
  const seconds = duration % 60
  const min = ((duration - seconds) / 60) % 60
  const hour = (duration - seconds - min * 60) / 3600

  return (
    (hour > 10 ? hour : '0' + hour) +
    ':' +
    (min > 10 ? min : '0' + min) +
    ':' +
    (seconds > 10 ? seconds : '0' + seconds)
  )
}

export const statusFormatter = (status: number) => {
  switch (status) {
    case 1:
      return '待支付'
    case 2:
      return '已完成'
    default:
      return '已取消'
  }
}
